package com.labbit.platform.manager.controller;

import com.labbit.platform.commons.constants.APIModules;
import com.labbit.platform.commons.domain.vo.Result;
import com.labbit.platform.commons.validator.ValidGroup;
import com.labbit.platform.manager.domain.bo.AdminUserBO;
import com.labbit.platform.manager.domain.query.UserQuery;
import com.labbit.platform.manager.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 用户控制器
 * @Author: CHEN YU
 * @Date: 2020-12-22 22:29
 **/
@Api(tags = APIModules.USER_MODULES)
@RestController
@RequestMapping("user")
@Slf4j
public class UserController {

    @Autowired
    private AdminUserService userService;

    @ApiOperation(value = "用户注册")
    @PostMapping
    public Result userRegister(@Validated @RequestBody AdminUserBO adminUserBO){
        log.debug("用户注册: {}", adminUserBO);
        userService.userRegister(adminUserBO);
        return Result.success();
    }

    @GetMapping("list")
    public Result userList(UserQuery userQuery){
        return Result.success(userService.userList(userQuery));
    }

    @DeleteMapping("{userId}")
    public Result deleteUser(@PathVariable("userId") String userId){
        userService.deleteUser(userId);
        return Result.success();
    }

    @GetMapping("{userId}")
    public Result getUserById(@PathVariable("userId") String userId){
        return Result.success(userService.getUserInfoById(userId));
    }

    @PutMapping
    public Result updateUser(@Validated(ValidGroup.Update.class) @RequestBody AdminUserBO adminUserBO){
        userService.updateUser(adminUserBO);
        return Result.success();
    }

}
